<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
  <style>td{width: 100px}</style>
</head>
<body>
<table border="1">
  <caption>个人信息</caption>
  <tr><td>照片:</td><td id="pic_td"></td></tr>
  <tr><td>姓名:</td><td id="name_td"></td></tr>
  <tr><td>年龄:</td><td id="age_td"></td></tr>
  <tr><td>好友:</td><td id="friends_td"></td></tr>
</table>
<input type="button" value="加载数据" onclick="f()">
<script>
  function f() {
      //假设下面的对象是从服务器请求回来的数据
    let person = {name:"传奇哥",age:18,url:"../b.jpg",
        friends:["孙尚香","虞姬","武则天"]}
      //得到页面中的td
      let nameTd = document.querySelector("#name_td");
      let ageTd = document.querySelector("#age_td");
      let picTd = document.querySelector("#pic_td");
      let friendsTd = document.querySelector("#friends_td");
      //把person对象中的数据赋值给td
      nameTd.innerText = person.name;
      ageTd.innerText = person.age;
      //创建图片标签添加到td中
      let img = document.createElement("img");
      img.src = person.url;
      img.width = 100;
      picTd.append(img);
      //创建无序列表并添加到td中
      let ul = document.createElement("ul");
      //遍历好友名字
      for (let friend of person.friends) {
          let li = document.createElement("li");
          li.innerText = friend;
          ul.append(li);
      }
      friendsTd.append(ul);




  }
</script>
</body>
</html>



















